(function () {
	var $AjaxUpload = function (url, success, error) {
		this.url = url;
		this.data = new FormData();
        this.data.append("action", url);
		this.async = false;
		this.success = success;
		this.error = error;
	};

    $AjaxUpload.prototype = {
		start : function () {	
			var me = this;
			
			if (this.url.indexOf("?") == -1) {
				this.url = this.url + "?jstime=" + new Date().getTime();
			} else {
				this.url = this.url + "&jstime=" + new Date().getTime();
			}
			$.ajax({
		        type: "post",//上传必须是post
		        url: this.url,
		        dataType: "json",
		        async: this.async,
		        data: this.data,
                contentType: false, //必须
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
				beforeSend: function(data) {
					
				},
		        success: function(data) {
		        	me.success(data);
		        },
		        error: function(data) {
		        	me.error(data);
		        }
		    });
		}, 
		set : function (name, value) {
            this.data.append(name, value);
			return this;
		},
		clear : function () {
			this.data = new FormData();
            this.data.append("action", this.url);
			return this;
		}
	};
	
	window.$AjaxUpload = $AjaxUpload;
	
} ());